﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Phoenix.Xna.Framework.Serialization;
using Phoenix.Xna.Framework.Input.Binding;
using System.Xml.Linq;
using Microsoft.Xna.Framework.Input;

namespace InputBindingStudio
{
    using Phoenix.Xna.Framework.Input.Binding;

    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public static readonly DependencyProperty BindingsProperty = DependencyProperty.Register("Bindings", typeof(Dictionary<string, InputBindingCollection>), typeof(Window1));

        [SerializableIDictionary]
        public Dictionary<string, InputBindingCollection> Bindings
        {
            get { return (Dictionary<string, InputBindingCollection>)GetValue(BindingsProperty); }
            set { SetValue(BindingsProperty, value); }
        }

        public Window1()
        {
            InitializeComponent();
            Bindings = new Dictionary<string, InputBindingCollection>();
        }

        private void NewBindingClick(object sender, RoutedEventArgs e)
        {
            //BindingDialog bd = new BindingDialog();

            //if (bd.ShowDialog().Value)
            //{
            //    InputBinding b = bd.Binding;
            //    InputBindingCollection c = new InputBindingCollection()
            //    {
            //        ID = "Application"
            //    };
            //    c.Add(b);
            //    Bindings.Add("Application", c);
            //    Serializer s = new Serializer();
            //    XElement x = s.SerializeAsXElement(Bindings);
            //    x.Save("InputBindings.xml");
            //}
            Dictionary<string, InputBindingCollection> d = new Dictionary<string, InputBindingCollection>();
            InputBindingCollection bc = new InputBindingCollection()
            {
                ID = "Game"
            };
            CompositeInputBinding<Keys> b = new CompositeInputBinding<Keys>()
            {
                Action = "Exit",
                DeviceType = Phoenix.Xna.Framework.Input.DeviceType.Keyboard,
                SubDeviceType = Phoenix.Xna.Framework.Input.DeviceSubType.KeyboardKey,
                Value = new List<Keys>() { Keys.Escape }
            };
            bc.Add(b);
            d.Add("Game", bc);
            Serializer s = new Serializer();
            XElement x = s.SerializeAsXElement(d);
            x.Save("InputBindings.xml");
        }

        private void OnNewCollectionClick(object sender, RoutedEventArgs e)
        {

        }
    }
}
